package com.david.controller;

import com.david.service.IUserService;
import com.david.vo.LoginVo;
import com.david.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


/**
 * @program: Secondskill-Demo
 * @description: 登录
 * @author: David
 * @version:
 * @create: 2022-04-11 22:45
 **/
@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Resource
    IUserService userService;

    /**
     * 跳转登录页面
     * 请求方式 Post
     * @return
     */
    @RequestMapping("/toLogin")
    public ModelAndView ToLogin(){
        ModelAndView view = new ModelAndView();
        view.setViewName("login");
        return view;
    }

    /**
     * 登录功能
     * @param loginVo
     * @return
     */
    @RequestMapping("/doLogin")
    public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response){
        return userService.doLogin(loginVo,request,response);
    }
}
